package com.aricwang.easyprofile.database;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class PlaceTable {
	// Database table
	public static final String TABLE_NAME = "places";
	
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NAME = "name";
	public static final String COLUMN_ADDRESS = "address";
	
	public static final String COLUMN_LATITUDE = "latitude";
	public static final String COLUMN_LONGITUDE = "longitude";
	public static final String COLUMN_RADIUS = "radius";
		
	public static final String[] ALL_COLUMNS = { 
		PlaceTable.COLUMN_ID,
		PlaceTable.COLUMN_NAME,
		PlaceTable.COLUMN_ADDRESS,
		PlaceTable.COLUMN_LATITUDE,
		PlaceTable.COLUMN_LONGITUDE,
		PlaceTable.COLUMN_RADIUS,
	};

	// Database creation SQL statement
	private static final String DATABASE_CREATE = "create table " 
			+ TABLE_NAME
			+ " (" 
			+ COLUMN_ID + " integer primary key autoincrement, " 
			+ COLUMN_NAME + " text not null, " 
			+ COLUMN_ADDRESS + " text , "
			+ COLUMN_LATITUDE + " float default 0, "
			+ COLUMN_LONGITUDE + " float default 0, "
			+ COLUMN_RADIUS + " integer default 500"
			+ ");";

	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
		insertDefaults(database);
	}

	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		Log.w(ProfileTable.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		
		onCreate(database);
	}
	
	private static void insertDefaults(SQLiteDatabase database) {
		// profile 'Default'
	}
	
//	private static void insertRecord(SQLiteDatabase database, String name, 
//			int priority, int profile, int timeframeStartHour, int timeframeStartMinute,
//			int timeframeEndHour, int timeframeEndMinute, int timeframeRepeat, 
//			int charging, int place) 
//	{
//		String sql = "insert into " + TABLE_NAME  
//				+ " ( "
//				+ COLUMN_NAME + ", " 
//				+ COLUMN_PRIORITY + ", "
//				+ COLUMN_PROFILE + ", "
//				+ COLUMN_TIMEFRAME_START_HOUR + ", "
//				+ COLUMN_TIMEFRAME_START_MINUTE + ", "
//				+ COLUMN_TIMEFRAME_END_HOUR + ", "
//				+ COLUMN_TIMEFRAME_END_MINUTE + ", "
//				+ COLUMN_TIMEFRAME_REPEAT + ", "
//				+ COLUMN_CHARGING + ", "
//				+ COLUMN_PLACE
//				+ ") values ( '"
//				+ name + "', "
//				+ priority + ", "
//				+ profile + ", "
//				+ timeframeStartHour + ", "
//				+ timeframeStartMinute + ", "
//				+ timeframeEndHour + ", "
//				+ timeframeEndMinute + ", "
//				+ timeframeRepeat + ", "
//				+ charging + ", "
//				+ place 
//				+ " );";
//	
//		database.execSQL(sql);
//	}	
}
